﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using QA_System.QASysDataSetTableAdapters;

namespace QA_System
{
    public class Artist
    {
        private static ARTISTTableAdapter artistAdapter = new ARTISTTableAdapter();
        public static QASysDataSet.ARTISTDataTable GetAllArtist()
        {
            QASysDataSet.ARTISTDataTable artistTable = artistAdapter.GetData();
            return artistTable;            
        }

        public static Artistfield GetByArtistId(int artistId)
        {
            QASysDataSet.ARTISTDataTable artistTable = artistAdapter.GetDataByArtistId(artistId);
            if (artistTable.Rows.Count == 0)
                return null;
            else
            {
                Artistfield FData = new Artistfield();
                FData.Art_ID = int.Parse(artistTable.Rows[0]["Art_Id"].ToString());
                FData.Art_Name = artistTable.Rows[0]["Name"].ToString();
                FData.Art_Birth = DateTime.Parse(artistTable.Rows[0]["Birth"].ToString());
                FData.Art_Nationality = artistTable.Rows[0]["Nationality"].ToString();
                FData.Artist_Gen = bool.Parse(artistTable.Rows[0]["Male"].ToString());
                if (artistTable.Rows[0]["Death"].ToString() != "")
                    FData.Art_Death = DateTime.Parse(artistTable.Rows[0]["Death"].ToString());
                if (artistTable.Rows[0]["Address"].ToString() != "")
                    FData.Art_Address = artistTable.Rows[0]["Address"].ToString();
                if (artistTable.Rows[0]["Email"].ToString() != "")
                    FData.Art_Email = artistTable.Rows[0]["Email"].ToString();
                if (artistTable.Rows[0]["Description"].ToString() != "")
                    FData.Description = artistTable.Rows[0]["Description"].ToString();
                return (FData);
            }         
        }

        public static Artistfield GetByArtistName(string artistName)
        {
            QASysDataSet.ARTISTDataTable artistTable = artistAdapter.GetDataByArtistName(artistName);
            if (artistTable.Rows.Count == 0)
                return null;
            else
            {
                Artistfield FData = new Artistfield();
                FData.Art_ID = int.Parse(artistTable.Rows[0]["Art_Id"].ToString());
                FData.Art_Name = artistTable.Rows[0]["Name"].ToString();
                FData.Art_Birth = DateTime.Parse(artistTable.Rows[0]["Birth"].ToString());
                FData.Art_Nationality = artistTable.Rows[0]["Nationality"].ToString();
                FData.Artist_Gen = bool.Parse(artistTable.Rows[0]["Male"].ToString());
                if(artistTable.Rows[0]["Death"].ToString() != "")
                    FData.Art_Death = DateTime.Parse(artistTable.Rows[0]["Death"].ToString());
                if (artistTable.Rows[0]["Address"].ToString() != "")
                    FData.Art_Address = artistTable.Rows[0]["Address"].ToString();
                if (artistTable.Rows[0]["Email"].ToString() != "")
                    FData.Art_Email = artistTable.Rows[0]["Email"].ToString();
                if (artistTable.Rows[0]["Description"].ToString() != "")
                    FData.Description = artistTable.Rows[0]["Description"].ToString();
                return FData;
            }
        }

        public static string GetAllArtName()
        {
            QASysDataSet.ARTISTDataTable artistTable = artistAdapter.GetData(); 
            string temp = "";
            if (artistTable.Rows.Count > 0)                
            {
                for (int i = 0; i < artistTable.Rows.Count; i++) temp += artistTable.Rows[i]["Name"].ToString() + "/";                    
            }
            return temp;
        }

        public static string GetAllNationality()
        {
            QASysDataSet.ARTISTDataTable artistTable = artistAdapter.GetData();  
            string temp = "";
            List<string> nationalityList = new List<string>();
            foreach (var row in artistTable)
            {
                nationalityList.Add(row.Nationality);
            }
            foreach (var item in nationalityList.Distinct())
            {
                temp += item + "/";
            }
            return temp;            
        }
    }
}
